package sunproject;

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class PlaneTarium extends Frame {

    Image sun = Toolkit.getDefaultToolkit().getImage("image/sun2.jpg");
    double x;
    double y;
    double drgee = 3.14 / 3;

    public void paint(Graphics g) {
        g.drawImage(sun, (int) x, (int) y, null);
        x = x + 100 * Math.cos(drgee);
        y = y + 80 * Math.sin(drgee);
        if (y > 900 || y < 0) {
            drgee = -drgee;
        }
        if (x > 1800 || x < 0) {
            drgee = 3.14 - drgee;
        }
    }

    void launchFrame() {
        setSize(1800, 900);
        setLocation(50, 50);
        setTitle("韩二冰作品");
        setBackground(Color.white);
        setVisible(true);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        new PaintThread().start();

    }

    public static void main(String[] args) {
        System.out.println("太阳系模型");
        new PlaneTarium().launchFrame();

    }

    class PaintThread extends Thread {
        public void run() {
            while (true) {
                repaint();
                try {
                    Thread.sleep(40);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
